package com.mzx.javase.io;

import javax.lang.model.element.VariableElement;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 类描述：IO流四大家族首领，
 * InputStream
 * OutputStream
 * Reader
 * Writer
 *
 * @ClassName FileInputStreamTest
 * @Description TODO
 * @Author 马子鑫
 * @Date 2022/7/19 16:54
 * @Version 1.0
 */
public class FileInputStreamTest {
    public static void main(String[] args) {
        FileInputStream fis = null;
        try {
//            fis = new FileInputStream("D:\\java\\tempdirectory\\test01.txt");
            fis = new FileInputStream("fos.txt");
            //一个字节一个字节读
//            int a = fis.read();
//            System.out.println(a);
            byte[] bytes = new byte[4];
//            int read = fis.read(bytes);
//            System.out.println(read);
            int readLength = 0;
            while ((readLength = fis.read(bytes)) != -1) {
                String s = new String(bytes,0,readLength);
                System.out.println(s);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
